package com.usian.search.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.search.dtos.UserSearchDto;
import com.usian.model.search.pojos.ApAssociateWords;
import com.usian.search.mapper.ApAssociateWordsMapper;
import com.usian.search.service.ApAssociateWordsService;
import org.springframework.stereotype.Service;

@Service
public class ApAssociateWordsServiceImpl extends ServiceImpl<ApAssociateWordsMapper, ApAssociateWords> implements ApAssociateWordsService {
    @Override
    public ResponseResult search(UserSearchDto dto) {

        if(dto.getPageSize()>20){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID,"参数不存在");
        }

        Page pageParam = new Page(dto.getPageNum(), dto.getPageSize());

        IPage result = page(pageParam, Wrappers.<ApAssociateWords>lambdaQuery().like(ApAssociateWords::getAssociateWords, dto.getSearchWords()));

        return ResponseResult.okResult(result.getRecords());
    }
}
